const { DataTypes } = require('sequelize');
// const bcrypt = require("bcryptjs");

const seq = require('../../db/sql');

const user = seq.define('t_user', {
  user_name: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    comment: 'username only',
  },
  password: {
    type: DataTypes.CHAR(64),
    allowNull: false,
    comment: 'password',
    // set(val) {
    //   const salt = bcrypt.genSaltSync(10);

    //   const value = bcrypt.hashSync(val, salt);

    //   this.setDataValue("password", value);
    // },
  },
  is_admin: {
    type: DataTypes.ENUM('0', '1', '2'),
    allowNull: false,
    defaultValue: '0',
    comment: '用户权限等级: 0=普通用户, 1=管理员, 2=超级管理员',
  },
});

// user.sync({ alter: true });

module.exports = user;
